package cn.laike.modules.dev.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import cn.laike.common.utils.PageUtils;
import cn.laike.common.utils.Query;
import cn.laike.modules.dev.dao.HotelDao;
import cn.laike.modules.dev.entity.HotelEntity;
import cn.laike.modules.dev.service.HotelService;
import cn.laike.modules.sys.shiro.ShiroUtils;


@Service("hotelService")
public class HotelServiceImpl extends ServiceImpl<HotelDao, HotelEntity> implements HotelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
    	//酒店名称
    	String name = (String)params.get("name");	
    	Integer hotelId = ShiroUtils.getHotelId();
        Page<HotelEntity> page = this.selectPage(
                new Query<HotelEntity>(params).getPage(),
                new EntityWrapper<HotelEntity>()
                .eq(ShiroUtils.isAdmin(),"uid", ShiroUtils.getUserId())
                .eq((hotelId != null && hotelId > 0), "id", hotelId)
                .like(StringUtils.isNotEmpty(name), "name", name)
                .eq("del_flag", "0")
                .orderBy("sort", false)
        );

        return new PageUtils(page);
    }
    
	@Override
	public HotelEntity getHotel(Integer id) {
		List<HotelEntity> list = baseMapper.getHotel(id);
		return (list != null && list.size() >0) ? list.get(0) : null;
	}

	@Override
	public List<HotelEntity> queryHotelList(Long uid, Integer cityId, String name) {
		if(StringUtils.isNotEmpty(name)) {
			name = "%"+name+"%";
		}
		return baseMapper.queryHotelList(uid, cityId, name);
	}

	@Override
	public Map<String, Integer> getHotelCount(Long uid) {
		return baseMapper.getHotelCount(uid);
	}

	@Override
	public List queryHotelNameList(Long uid) {
		return baseMapper.queryHotelNameList(uid);
	}



}
